import axios from "axios";
import { getToken } from "./token";
import NProgress from "nprogress";
import "nprogress/nprogress.css";

axios.defaults.baseURL = "http://127.0.0.1:8888/api/private/v1";

//请求拦截器
axios.interceptors.request.use(
  config => {
    //在发送请求前
    config.headers.Authorization = getToken();
    //显示进度条
    NProgress.start();
    return config;
  },
  error => {
    //请求错误
    return Promise.reject(error);
  }
);

//响应拦截器
axios.interceptors.response.use(response => {
  //影藏进度条
  NProgress.done();
  //响应数据
  return response.data;
});

export default axios; //直接返回axios;
